#include "Point.h"

sbit SRCLK=P3^6;
sbit RCLK=P3^5;
sbit SER=P3^4;

void Hc595SendByte(uchar dat)
{
	uchar a;
	SRCLK=0;
	RCLK=0;
	for(a=0;a<8;a++)
	{
		SER=dat>>7;
		dat<<=1;
		
		SRCLK=1;
		_nop_();
		_nop_();
		SRCLK=0;
	}
	RCLK=1;
	_nop_();
	_nop_();
	RCLK=0;
}

void DisplayPoint(int x ,int y)
{
	uchar xdat;
	uchar ydat;
	
	switch(x)
	{
		case 0 : xdat=0xff  ;break;
		case 1 : xdat=0x7f  ;break;
		case 2 : xdat=0xbf  ;break;
		case 3 : xdat=0xdf  ;break;
		case 4 : xdat=0xef  ;break;
		case 5 : xdat=0xf7  ;break;
		case 6 : xdat=0xfb  ;break;
		case 7 : xdat=0xfd  ;break;
		case 8 : xdat=0xfe  ;break;
		}
	switch(9-y)
	{
		case 0 : ydat=0x00  ;break;
		case 1 : ydat=0x80  ;break;
		case 2 : ydat=0x40  ;break;
		case 3 : ydat=0x20  ;break;
		case 4 : ydat=0x10  ;break;
		case 5 : ydat=0x08  ;break;
		case 6 : ydat=0x04  ;break;
		case 7 : ydat=0x02  ;break;
		case 8 : ydat=0x01  ;break;
		}
	Hc595SendByte(ydat);
	P0=xdat;   
}
void DisplayAll(uchar *All)
{
	uchar i;
	uchar ledwei[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};

	for(i=0;i<8;i++)
		{
			P0=ledwei[i];
			Hc595SendByte(All[i]);
			Hc595SendByte(0x00);
		}
	
}

void DisplayNumber(uchar num)
{
	uchar code number[10][8]={{0x00,0x00,0x3C,0x42,0x42,0x3C,0x00,0x00,},//0
												 {0x00,0x00,0x00,0x22,0x7E,0x02,0x00,0x00,},//1
												 {0x00,0x00,0x26,0x4A,0x52,0x22,0x00,0x00,},//2
												 {0x00,0x00,0x24,0x42,0x4A,0x5E,0x24,0x00,},//3
												 {0x00,0x08,0x18,0x28,0x7E,0x08,0x00,0x00,},//4
												 {0x00,0x00,0x3A,0x2A,0x2A,0x2E,0x00,0x00,},//5
												 {0x00,0x00,0x7E,0x4A,0x4A,0x4E,0x00,0x00,},//6
												 {0x00,0x00,0x40,0x4E,0x58,0x70,0x00,0x00,},//7
												 {0x00,0x00,0x2C,0x52,0x52,0x2C,0x00,0x00,},//8
												 {0x00,0x00,0x30,0x4A,0x4A,0x3C,0x00,0x00,} //9
											 };
	DisplayAll(number[num]);
}
	